﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：凭证列表
 */
var refreshGirdData; // 更新数据
var selectedRow;

var companyId = '';
var ztId = '';
var kjnd = '';
var kjkm = [];
var aj = [];
var pjh = [];
var zph = [];
var wldx = [];
var xm = [];
var bm = [];

var userId = '';
var userName = '';
var userdefault = {};
var params = {};
var flag = false;

var bootstrap = function ($, learun) {
    "use strict";

    var pageWidth = 1024;

    var page = {
        init: function () {
            //初始化打印插件
            hiprint.init();
            pageWidth = ($('#gridtable').width());
            var loginInfo = learun.clientdata.get(['userinfo']);
            userdefault = learun.clientdata.get(['usersetting']);

            userId = loginInfo.user.id;
            userName = loginInfo.user.realName;

            page.initGrid(false, 50);
            page.bind();

        },
        bind: function () {
            $('#multiple_condition_query').lrMultipleQuery(function (queryJson) {
                // 调用后台查询
                // queryJson 查询条件
                page.search(queryJson);

            }, 450, 980);
            $('#pzrqMonth').lrselect({
                type: 'default',
                // 展开最大高度
                maxHeight: 300,
                placeholder: '月份',
                data: [
                    {'id': '01', 'text': '01'},
                    {'id': '02', 'text': '02'},
                    {'id': '03', 'text': '03'},
                    {'id': '04', 'text': '04'},
                    {'id': '05', 'text': '05'},
                    {'id': '06', 'text': '06'},
                    {'id': '07', 'text': '07'},
                    {'id': '08', 'text': '08'},
                    {'id': '09', 'text': '09'},
                    {'id': '10', 'text': '10'},
                    {'id': '11', 'text': '11'},
                    {'id': '12', 'text': '12'}
                ],
                select: function (item) {
                    if (!item || item.id == '-1') {
                        var beginDate = kjnd + "-01-01";
                        var day = new Date(kjnd, 12, 0);
                        var endDate = kjnd + "-" + 12 + "-" + day.getDate();
                        $("#pzrqStart").val(beginDate);
                        $("#pzrqEnd").val(endDate);
                    } else {
                        var kjqj = item.id;
                        var beginDate = kjnd + "-" + kjqj + "-01";
                        var day = new Date(kjnd, kjqj, 0);
                        var endDate = kjnd + "-" + kjqj + "-" + day.getDate();
                        $("#pzrqStart").val(beginDate);
                        $("#pzrqEnd").val(endDate);
                    }
                }
            });
            // 公司选择
            $('#company_select').lrselect({
                type: 'tree',
                // placeholder: '请选择机构',
                height: 300,
                maxHeight: 300,
                // 是否允许搜索
                //allowSearch: true,
                select: function (item) {
                    if (item && item.value != '-1') {
                        companyId = item.value;

                        $('#zt_select').lrselectRefresh({
                            // 访问数据接口地址
                            url: config.base_server() + 'zts/dropdownlist?access_token=' + config.getToken().access_token,
                            // 访问数据接口参数
                            param: {companyId: companyId},
                            select: function (ztItem) {
                                if (!ztItem || ztItem.value == '-1') {
                                    ztId = "";
                                } else {
                                    ztId = ztItem.value;
                                    $('#kjnd_select').lrselectRefresh({
                                        // 访问数据接口地址
                                        url: config.base_server() + 'kjnds/dropdownlist?access_token=' + config.getToken().access_token,
                                        // 访问数据接口参数
                                        param: {companyId: companyId, ztId: ztItem.value},
                                    }).lrselectSet(userdefault.kjnd);
                                }
                            }
                        }).lrselectSet(userdefault.ztId);
                    }
                }
            });
            $('#company_select').lrselectRefresh({
                // 访问数据接口地址
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                // 访问数据接口参数
                param: {parentId: '0'}
            }).lrselectSet(userdefault.companyId);
            // 帐套选择
            $('#zt_select').lrselect({
                type: 'default',
                //placeholder: '请选择帐套',
                // 展开最大高度
                maxHeight: 300
            });
            // 会计年度选择
            $('#kjnd_select').lrselect({
                type: 'default',
                //placeholder: '请选择会计年度',
                // 展开最大高度
                maxHeight: 300,
                select: function (item) {
                    if (!item || item.value == '-1') {
                        kjnd = '';
                    } else {
                        kjnd = item.value;

                        var beginDate = kjnd + "-01-01";
                        var day = new Date(kjnd, 12, 0);
                        var endDate = kjnd + "-12-" + day.getDate();
                        $("#pzrqStart").val(beginDate);
                        $("#pzrqEnd").val(endDate);

                        $('#kjkmCodes').lrlayerselect({
                            dataValueId: 'code',
                            dataTextId: 'codeAndName',
                            reset: true,
                            url: config.base_server() + 'kjkms/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '科目', name: 'codeAndName', width: 225, align: 'left'},
                                {
                                    label: "余额方向", name: "yefx", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "借" : "贷";
                                    }
                                },
                                {
                                    label: "项目", name: "isXmHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {
                                    label: "部门", name: "isBmHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {
                                    label: "案件", name: "isAjHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {
                                    label: "票据号", name: "isPjhHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {
                                    label: "支票号", name: "isZphHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {
                                    label: "往来", name: "isWlHs", width: 50, align: "center",
                                    formatter: function (cellvalue) {
                                        return cellvalue == 1 ? "是" : "";
                                    }
                                },
                                {label: '是否明细', name: 'isMx', width: 1, align: 'left', hidden: true},
                                {label: '编号', name: 'code', width: 120, align: 'left', hidden: true},
                                {label: '简称', name: 'simpleName', width: 225, align: 'left', hidden: true}
                            ],
                            select: function (values, texts) {
                                kjkm = values;
                            }
                        });
                        $('#xmCodes').lrlayerselect({
                            dataValueId: 'code',
                            dataTextId: 'codeAndName',
                            reset: true,
                            url: config.base_server() + 'xms/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'codeAndName', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                                {label: '编号', name: 'code', width: 120, align: 'left'},
                            ],
                            select: function (values, texts) {
                                xm = values;
                            }
                        });
                        $('#bmCodes').lrlayerselect({
                            dataValueId: 'code',
                            dataTextId: 'codeAndName',
                            reset: true,
                            url: config.base_server() + 'departments?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'codeAndName', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                                {label: '编号', name: 'code', width: 120, align: 'left'},
                            ],
                            select: function (values, texts) {
                                bm = values;
                            }
                        });
                        $('#ajCodes').lrlayerselect({
                            dataValueId: 'name',
                            dataTextId: 'name',
                            enableInput: true,
                            reset: true,
                            url: config.base_server() + 'ajs/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'name', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                            ],
                            select: function (values, texts) {
                                aj = values;
                            }
                        });
                        $('#pjhCodes').lrlayerselect({
                            dataValueId: 'name',
                            dataTextId: 'name',
                            enableInput: true,
                            reset: true,
                            url: config.base_server() + 'pjhs/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&type=1' + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'name', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                            ],
                            select: function (values, texts) {
                                pjh = values;
                            }
                        });
                        $('#zphCodes').lrlayerselect({
                            dataValueId: 'name',
                            dataTextId: 'name',
                            enableInput: true,
                            reset: true,
                            url: config.base_server() + 'pjhs/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&type=2' + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'name', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                            ],
                            select: function (values, texts) {
                                zph = values;
                            }
                        });
                        $('#wldxCodes').lrlayerselect({
                            dataValueId: 'code',
                            dataTextId: 'codeAndName',
                            enableInput: true,
                            reset: true,
                            url: config.base_server() + 'wldxs/list?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&status=1' + '&access_token=' + config.getToken().access_token,
                            grid: [
                                {label: '名称', name: 'codeAndName', width: 225, align: 'left'},
                                {label: '备注', name: 'remark', width: 225, align: 'left'},
                                {label: '编号', name: 'code', width: 120, align: 'left', hidden: true},
                            ],
                            select: function (values, texts) {
                                wldx = values;
                            }
                        });
                        page.search();
                    }
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                page.search(params);
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                if (!companyId) {
                    learun.alert.error('请选择机构！');
                    return false;
                }
                if (!ztId) {
                    learun.alert.error('请选择帐套！');
                    return;
                }
                if (!kjnd) {
                    learun.alert.error('请选择会计年度！');
                    return;
                }
                learun.frameTab.open({
                    id: 'pz_add',
                    css: 'fa fa-file-text-o',
                    name: '新增凭证',
                    path: config.webportal_server + 'pages/finance/pz/tree.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&userId=' + userId + '&userName=' + encodeURI(encodeURI(userName)) + '&access_token=' + config.getToken().access_token
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (ztId == '') {
                    learun.alert.error('请选择帐套！');
                    return;
                }
                if (kjnd == '') {
                    learun.alert.error('请选择会计年度！');
                    return;
                }
                if (keyValue.indexOf(',') > 0) {
                    learun.alert.error('只能选择单条记录编辑！');
                    return;
                }
                if (learun.checkrow(keyValue)) {
                    learun.frameTab.open({
                        id: 'pz_edit',
                        css: 'fa fa-file-text-o',
                        name: '编辑凭证',
                        path: config.webportal_server + 'pages/finance/pz/tree.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&userId=' + userId + '&userName=' + encodeURI(encodeURI(userName)) + '&keyValue=' + keyValue + '&access_token=' + config.getToken().access_token
                    });
                }
            });
            // 查看
            $('#lr_view').on('click', function () {
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                var keyValue = $('#gridtable').jfGridValue('pzid');
                var pzh = $('#gridtable').jfGridValue('pzh');
                if (keyValue.indexOf(",") > 0) {
                    learun.alert.warning('仅支持单个凭证查看！');
                    return;
                }
                if (learun.checkrow(keyValue)) {
                    learun.frameTab.open({
                        id: 'pz_view' + pzh,
                        css: 'fa fa-file-text-o',
                        name: '查看凭证' + pzh,
                        path: config.webportal_server + 'pages/finance/pz/view.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&keyValue=' + keyValue + '&access_token=' + config.getToken().access_token
                    });
                }
            });
            // 开启多选
            $('#lr_multiselect').on('click', function () {
                flag = !flag;
                $('#gridtable').prop('outerHTML', '<div class="lr-layout-body" id="gridtable"></div>');
                setTimeout(function () {
                    page.initGrid(flag, 50);
                    page.search(params);
                }, 200);
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'pzs/delete?ids=' + keyValue + '&access_token=' + config.getToken().access_token, {id: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            // 审核
            $('#lr_auth').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认审核该项?', function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'pzs/auth?ids=' + keyValue + '&access_token=' + config.getToken().access_token, {id: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            // 取消审核
            $('#lr_un_auth').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认取消审核该项?', function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'pzs/unAuth?ids=' + keyValue + '&access_token=' + config.getToken().access_token, {id: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            // 打印
            $('#lr_preview').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (learun.checkrow(keyValue)) {
                    page.printPreview(keyValue);
                }
            });

            //检查异常凭证
            $('#lr_review').on('click', function () {
                learun.httpAsync2('GET', config.base_server() + 'pzs/findErrors?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&access_token=' + config.getToken().access_token, {}, function (res) {
                    if (res.resp_code == 200 && res.data.length > 0) {
                        var pzListStr = '';
                        for (var i = 0; i < res.data.length; i++) {
                            pzListStr += '<br/>' + res.data[i].kjqj + '月  (' + res.data[i].pzz + ')' + res.data[i].pzh
                        }
                        learun.alert.warning('存在异常凭证如下: ' + pzListStr);
                    } else {
                        learun.alert.info('未检测到异常凭证');
                    }
                })
            });

            // 导出pdf
            $('#lr_exportPdf').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('pzid');
                if (learun.checkrow(keyValue)) {
                    params.access_token = config.getToken().access_token;
                    params.ids = keyValue;
                    learun.download({
                        url: config.base_server() + 'pzs/export/pdf',
                        param: params
                    });
                }
            });
            // 导出pdf
            $('#lr_exportPdfAll').on('click', function () {
                params.access_token = config.getToken().access_token;
                learun.download({
                    url: config.base_server() + 'pzs/export/pdfAll',
                    param: params
                });
            });
        },
        initGrid: function (multi, rowsSize) {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'glvous/list?access_token=' + config.getToken().access_token,
                headData: [
                    {
                        label: "凭证日期", name: "pzrq", width: (pageWidth * (8 / 100)), align: "center",
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd');
                        }
                    },
                    {label: "凭证类型", name: "pzlxName", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "凭证号", name: "pzh", width: 80, align: "center"},
                    {
                        label: "临时/期初/结转",
                        name: "category",
                        width: (pageWidth * (8 / 100)),
                        align: "center",
                        sort: true,
                        formatter: function (cellvalue) {
                            if (cellvalue == 1) {
                                return "<span style='color: #f43838;'>临时凭证</span>";
                            } else if (cellvalue == 2) {
                                return "<span style='color: #2a00ff ;'>期初凭证</span>";
                            } else if (cellvalue == 3) {
                                return "<span style='color:#5ce638;'>结转凭证</span>";
                            }
                        }
                    },
                    {label: "摘要", name: "zy", width: (pageWidth * (27 / 100)), align: "left", sort: true},
                    {
                        label: "金额", name: "j", width: (pageWidth * (8 / 100)), align: "right", sort: true,
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {label: "制单员", name: "zdy", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "审核员", name: "shy", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "记账员", name: "jzy", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "出纳员", name: "cny", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "财务主管", name: "cwzg", width: (pageWidth * (7 / 100)), align: "center", sort: true},
                    {label: "pzid", name: "pzid", width: 1, align: "center", hidden: true}
                ],
                dblclick: function (row) {
                    if (!multi) {
                        if (row.pzid) {
                            var keyValue = row.pzid;
                            if (learun.checkrow(keyValue)) {
                                learun.frameTab.open({
                                    id: 'pz_view' + row.kjqj + '_' + row.pzh,
                                    css: 'fa fa-file-text-o',
                                    name: '查看凭证' + row.kjqj + '_' + row.pzh,
                                    path: config.webportal_server + 'pages/finance/pz/view.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&keyValue=' + keyValue + '&access_token=' + config.getToken().access_token
                                });
                            }
                        }
                    }
                },
                mainId: 'pzid',
                reloadSelected: true,
                isPage: true,
                rows: rowsSize,
                isMultiselect: multi
            });
        },
        search: function (param) {
            param = param || {};
            var pzrqStart = $("#pzrqStart").val();
            var pzrqEnd = $("#pzrqEnd").val();

            param.companyId = companyId;
            param.ztId = ztId;
            param.kjnd = kjnd;
            param.pzrqStart = pzrqStart;
            param.pzrqEnd = pzrqEnd;

            if ($.isArray(kjkm)) {
                param.kjkmCodes = kjkm.join();
            }
            if ($.isArray(aj)) {
                param.ajCodes = aj.join();
            }
            if ($.isArray(pjh)) {
                param.pjhCodes = pjh.join();
            }
            if ($.isArray(zph)) {
                param.zphCodes = zph.join();
            }
            if ($.isArray(wldx)) {
                param.wldxCodes = wldx.join();
            }
            if ($.isArray(xm)) {
                param.xmCodes = xm.join();
            }
            if ($.isArray(bm)) {
                param.bmCodes = bm.join();
            }
            if (!!param.pzhStart) {
                param.pzhStart = completePzh(param.pzhStart, 4);
            }
            if (!!param.pzhEnd) {
                param.pzhEnd = completePzh(param.pzhEnd, 4);
            }
            if ($("#ajCodes_input").val().trim() == "") {
                param.ajCodes = "";
            }
            if ($("#pjhCodes_input").val().trim() == "") {
                param.pjhCodes = "";
            }
            if ($("#zphCodes_input").val().trim() == "") {
                param.zphCodes = "";
            }
            if ($("#wldxCodes_input").val().trim() == "") {
                param.wldxCodes = "";
            }
            params = param;
            $('#gridtable').jfGridSet('reload', param);
        },

        // 凭证打印
        printPreview: function (ids) {
            var hiprintTemplate = null;
            learun.httpAsyncGet2(config.base_server() + 'printTempletes/findByCode', "&companyId=" + companyId + '&ztId=' + ztId + '&code=pz', function (res) {
                if (res.resp_code == 200) {
                    hiprintTemplate = new hiprint.PrintTemplate({
                        template: JSON.parse(res.data.templete),
                        settingContainer: '#PrintElementOptionSetting',
                        paginationContainer: '.hiprint-printPagination'
                    });

                    learun.httpAsyncGet2(config.base_server() + 'pzs/findByIds', "&ids=" + ids, function (res) {
                        if (res.resp_code == 200) {
                            var jsonData = [];

                            for (var i = 0; i < res.data.length; i++) {
                                var item = {};
                                var pzh = "(" + res.data[i].pzz + ")" + res.data[i].pzh;
                                item.pzh = pzh;
                                var pzrqArr = res.data[i].pzrq.split("-");
                                item.pzrq = pzrqArr[0] + "年" + pzrqArr[1] + "月" + pzrqArr[2] + "日";
                                item.zdy = res.data[i].zdy;
                                item.shy = res.data[i].shy;
                                item.jzy = res.data[i].jzy;
                                item.cwzg = res.data[i].cwzg;
                                item.ztName = res.data[i].ztName;
                                item.fj = res.data[i].fj;
                                item.total1 = "人民币" + res.data[i].total1;
                                item.total2 = $.formatMoney(res.data[i].total2, 2);
                                item.pzflList = res.data[i].pzflList;
                                for (var j = 0; j < item.pzflList.length; j++) {
                                    item.pzflList[j].j = $.formatMoney(item.pzflList[j].j, 2);
                                    item.pzflList[j].d = $.formatMoney(item.pzflList[j].d, 2);
                                    item.pzflList[j].ye = $.formatMoney(item.pzflList[j].ye, 2);
                                }

                                jsonData.push(item);
                            }
                            hiprintTemplate.resetPage();
                            // hiprintTemplate.print(jsonData);
                            $('#myModal .modal-body .prevViewDiv').html(hiprintTemplate.getHtml(jsonData));
                            $(".hiprint-printPaper div .hiprint-printElement-vline").each(function (i, item) {
                                var newHtml = $(this).prop("outerHTML")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 18pt; top: 699pt;\"></div>", "<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 18pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 424.5pt; top: 699pt;\"></div>", "<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 424.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 495.5pt; top: 699pt;\"></div>", "<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 495.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 566.5pt; top: 699pt;\"></div>", "<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 566.5pt; top: 695pt;\"></div>")
                                    .replace("<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 24pt; left: 18pt; top: 699pt;\"></div>", "<div class=\"hiprint-printElement hiprint-printElement-vline\" style=\"position: absolute; width: 9pt; height: 28pt; left: 18pt; top: 695pt;\"></div>");

                                $(this).prop("outerHTML", newHtml);
                            });

                            $('#myModal').modal('show');
                        }
                    });
                    $('#A4_printByHtml').click(function () {
                        hiprintTemplate.printByHtml($('#myModal .modal-body .prevViewDiv'));
                    })
                }
            });

        }
    };

    // 保存数据后回调刷新
    refreshGirdData = function () {
        page.search(params);
    };

    page.init();
}

//不足4位补0
function completePzh(num, length) {
    return (Array(length).join('0') + num).slice(-length);
}
